package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.activity.douluodalu.data.DouLuoDaLuUserData;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.douluodalu.CrossDouLouDaLuActivity;
import com.yanqu.road.server.manager.douluodalu.CrossDouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;


@Cmd(code = Protocol.C_DOU_LUO_DA_LU_PUSH_MSG_ACK, desc = "通知确认")
public class CrossDouLuoDaLuOnLinePushMsgACKCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuOnLineACKMsg ackMsg = DouLuoDaLuProto.DouLuoDaLuOnLineACKMsg.parseFrom(packet.getBytes());
        CrossDouLouDaLuActivity activity = CrossDouLuoDaLuMgr.getActivityOrNull(ackMsg.getActivityId(), groupId);
        if(activity != null){
            for (DouLuoDaLuProto.DouLuoDaLuOnLineACKTemp ackTemp : ackMsg.getAckList()) {
                int type = ackTemp.getType();
                if(type == 1){
                    for (long uid : ackTemp.getUserList()) {
                        DouLuoDaLuUserData userData = activity.getAllUserMap().get(uid);
                        if(userData != null){
                            userData.setLeaveTip(null);
                        }
                    }
                }else if(type == 2){
                    for (long uid : ackTemp.getUserList()) {
                        DouLuoDaLuUserData userData = activity.getAllUserMap().get(uid);
                        if(userData != null){
                            userData.setEnemyTipList(new ArrayList<>());
                        }
                    }
                }
            }
        }
    }

    @Override
    public void sendData() {

    }
}
